<extend name="_layout/main"/>
<block name="head">

</block>
<block name="top">
    <header class="mui-bar mui-bar1 mui-bar-nav mui-bar-nav1" id="header">
        <a class="btn" href="javascript:history.go(-1)">
            <i class="iconfont icon-fanhui"></i>
        </a>
        <div class="top-sch-box top-sch-boxtwo top-sch-boxthree flex-col">
            返回
        </div>
    </header>
</block>
<block name="content">
    <div class="warp warpthree clearfloat">
        <div class="h-top h-topone clearfloat box-s">
            <span>我的商品券</span>
            <p>{$wealth.coupon}</p>
        </div>
        <div class="recharge clearfloat">
            <div class="czhi clearfloat box-s">
                <p>转账数量</p>
                <input type="number" id="amount" name="amount" value="" placeholder="请输入商品券数量"/>
                <span></span>
            </div>
            <div class="czhi clearfloat box-s">
                <p>转入账户</p>
                <input type="text" id="username" name="username" value="" placeholder="请输入对方ID/手机号"/>
            </div>
            <div class="guize clearfloat box-s ra3">
                <h3>转账规则</h3>
                <div class="content clearfloat">
                    {$setting.transfer_annouce}
                </div>
            </div>
            <div class="bottom clearfloat">
                <a href="javascript:void(0)" id="btn-save" class="db fl btn ra3">确定</a>
                <a href="javascript:history.go(-1)" class="db fr btn ra3">取消</a>
            </div>
        </div>
    </div>
</block>
<block name="scripts">
    <script>
        $(document).on('keyup', '#amount', function (e) {
            var amount = $(this).val();
            if (isNaN(amount) || parseFloat(amount) < 1) {
                mui.alert('请输入合适的数量');
                $(this).val('');
                return;
            }
        })

        $(document).on('click', '#btn-save', function (e) {
            e.preventDefault();
            var amount = $("#amount").val();
            var username = $("#username").val();
            if (!amount || isNaN(amount) || parseFloat(amount) < 1) {
                mui.alert('请输入合适的数量', '错误');
                $('#amount').val('');
                return;
            }
            if (!username || username == '') {
                mui.alert('请输入对方ID/手机号', '错误');
                return;
            }
            mui.confirm('确认商品券转账'+amount+'给用户'+username+'吗？','警告',['确定','取消'],function (obj) {
                if(obj.index == 0){
                    $.post("{:U('Coupon/transfer')}", {amount: amount, username: username}, function (xdata) {
                        if (xdata.status == 'success') {
                            $("#amount").val('');
                            $("#username").val('');
                            mui.alert(xdata.message, '提示',function () {
                                document.location.href = xdata.data.url;
                            });
                        } else {
                            mui.alert(xdata.message, '错误');
                        }
                    }, 'json');
                }
            })

        })
    </script>
</block>
